//
//  ByCellCompensate.m
//  chequanbao_ios
//
//  Created by pro on 17/6/6.
//  Copyright © 2017年 com.itboye. All rights reserved.
//

#import "ByCellCompensate.h"

@implementation ByCellCompensate
{
    UIView          *_bgView;
    UIImageView     *_iconView;
    UILabel         *_titleLabel;
    UILabel         *_detailLabel;
}
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        
        self.backgroundColor = [UIColor clearColor];
        [self setupUI];
        
        
    }
    return self;
}
- (void)setupUI {
    
    _bgView = [[UIView alloc] init];
    _bgView.backgroundColor = [UIColor colorWithWhite:1 alpha:1];
    [self.contentView addSubview:_bgView];
    
    _iconView = [[UIImageView alloc] init];
    [_bgView addSubview:_iconView];
    
    _titleLabel = [[UILabel alloc] init];
    _titleLabel.adjustsFontSizeToFitWidth = YES;
    _titleLabel.font = FONT(15);
    _titleLabel.textColor = [UIColor grayColor];
    _titleLabel.textAlignment = NSTextAlignmentLeft;
    [_bgView addSubview:_titleLabel];
    
    
    _detailLabel = [[UILabel alloc] init];
    _detailLabel.adjustsFontSizeToFitWidth = YES;
    _detailLabel.font = FONT(15);
    _detailLabel.textColor = [UIColor grayColor];
    _detailLabel.textAlignment = NSTextAlignmentLeft;
    [_bgView addSubview:_detailLabel];
    
}

- (void)setDataDic:(NSDictionary *)dataDic {
    
    _dataDic = dataDic;
    
    [self setNeedsLayout];
}

- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    CGFloat bgLeft = SCREEN_WIDTH / 12;
    CGFloat margin = 10;
    CGFloat x, y, width, height;
    
    x = bgLeft;
    y = 0;
    width = SCREEN_WIDTH - bgLeft * 2;
    height = self.height;
    _bgView.layer.cornerRadius = 0;
    _bgView.frame = CGRectMake(x, y, width, height);
    
    x = margin;
    y = margin;
    height = self.height - y * 2;
    width = height / 3 * 4;
    _iconView.layer.cornerRadius = 0;
    _iconView.frame = CGRectMake(x, y, width, height);
    
    x = _iconView.right + margin;
    y = 0;
    width = _bgView.width - 10 - x;
    height = 20;
    _titleLabel.frame = CGRectMake(x, y, width, height);
    
    
    x = _titleLabel.left;
    y = 0;
    width = _bgView.width - 10 - x;
    height = 20;
    _detailLabel.frame = CGRectMake(x, y, width, height);
    
    
    /*
     "id": "1",
     "insurance_id": "5",
     "name": "测试理赔公司",
     "contact_number": "18768880000",
     "logo": "0",
     "link": "",
     "other_info": [],
     "status": "0"
     */
    /*
     模拟数据
     */
    NSString *logoStr = BOYE_PICTURE_VIEW_URL(_dataDic[@"logo"]);
    NSString *title = _dataDic[@"name"];
    NSString *detail = _dataDic[@"contact_number"];
    
    CGFloat remain = (_bgView.height - _titleLabel.height - _detailLabel.height) / 2;
    
    [_iconView setImageWithURL:[NSURL URLWithString:logoStr] placeholderImage:DEFAULT_IMAGE completed:nil];
    
    _titleLabel.top = remain;
    _titleLabel.text = title;
    
    _detailLabel.top = _titleLabel.bottom;
    _detailLabel.text = detail;
}
@end
